/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2023-10-24
 * Time: 20:10
 */
import java.util.Random;
import java.util.Scanner;
public class Test {


    public static void main(String[] args) {
        Random random = new Random();
        int n = random.nextInt(100);
        System.out.println("随机数"+n);
        Scanner scan = new Scanner(System.in);

        while (true) {
            System.out.println("输入你要猜的数字：");
            int num = scan.nextInt();
            if(num < n) {
                System.out.println("猜小了！");
            }else if(num > n) {
                System.out.println("猜大了！");
            }else {
                System.out.println("猜对了！");
                break;
            }
        }
    }

    //Java 当中 如何生成一个简单的随机数
    public static void main14(String[] args) {
        Random random = new Random();
        //int n = random.nextInt(100)+1;//[1-101)
        // int n = random.nextInt(51)+50;//[0-49] + 50
        int n = random.nextInt(102);//[0-49] + 50
        System.out.println(n);

        //Math.random(); todo:自主学习这个方法生成随机数！

    }

    public static void main13(String[] args) {
        Scanner scan = new Scanner(System.in);
        /*
        while (scan.hasNextInt()) {
            System.out.println("输入你的年龄：");
            int age = scan.nextInt();
            System.out.println("年龄：" + age);
        }
        */

        while (scan.hasNextLine()){
            System.out.println("输入你的姓名：");
            String name = scan.nextLine();
            System.out.println("姓名："+name);
        }
        //在cmd命令行窗口，结束的时候 使用ctr+z  IDEA上是CTR+D
    }

    public static void main12(String[] args) {
        //alt+回车   ctr+鼠标左键  System.in键盘
        Scanner scan = new Scanner(System.in);
        //int a = 10;

        System.out.println("输入你的姓名：");
        String name = scan.nextLine();
        System.out.println("姓名："+name);

        System.out.println("输入你的年龄：");
        int age = scan.nextInt();
        System.out.println("年龄："+age);

        System.out.println("输入你的工资：");
        float money = scan.nextFloat();
        System.out.println("工资："+money);

        scan.close();
    }

    public static void main11(String[] args) {
        System.out.println(10);//输出且换行
        System.out.print("不换行");
        System.out.printf("%s","这是格式化输出！");
    }


    public static void main10(String[] args) {
        //fori
        /*for (int i = 0; i < 100; i++) {
            System.out.println(i);
        }*/

       /* int sum = 0;
        for (int i = 1; i <= 5; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);*/

        /*for(;;){
            System.out.println("dsfafa");
        }*/

        //至少会执行一次 所以一般不怎么使用它
        int num = 1;
        do {
            System.out.println(num);
            num++;
        } while (num <= 0);

    }

    public static void main9(String[] args) {
        int i = 1;
        while (i <= 100) {
            if(i%15 != 0) {
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }

    public static void main8(String[] args) {
        int a = 10;
        while (a >= 0) {
            if(a == 9) {
                continue;
            }
            a--;
        }
    }




    public static void main7(String[] args) {
        /*int a = 1;
        while (true) {
            System.out.println("fasfa");
        }*/

        int num = 1;
        while (num <= 10) {
            System.out.println(num);
            num++;
        }

    }



    public static void main6(String[] args) {

        int ret2 = 0;
        int n = 1;
        while (n <= 5) {
            int i = 1;
            int ret = 1;
            while (i <= n) {
                ret *= i;
                i++;
            }
            ret2 += ret;
            n++;
        }
        System.out.println(ret2);
    }

    public static void main5(String[] args) {
        int i = 1;
        int ret = 1;
        while (i <= 5) {
            ret *= i;
            i++;
        }
        System.out.println(ret);
    }

    public static void main4(String[] args) {
        //1-100的和
        //1-100的奇数和
        //1-100的偶数和  快捷键可以自定义的
        int i = 1;
        int sum = 0;
        int sumOdd = 0;
        int sumEve = 0;
        while (i <= 100) {
            if(i%2 == 0) {
                sumEve += i;
            }else {
                sumOdd += i;
            }
            sum += i;
            i++;
        }
        System.out.println(sum);
        System.out.println(sumOdd);
        System.out.println(sumEve);
    }


    public static void main3(String[] args) {
        //1-10
        int i = 1;
        int sum = 0;
        while (i <= 10) {
            sum += i;
            i++;
        }
        System.out.println(sum);
    }

    public static void main2(String[] args) {
        //不能做switc的参数的数据类型是哪些？
        String  a = "hello";
        switch (a) {
            case "abc":
                System.out.println("two");
                break;
            case "hello":
                System.out.println("one");
                break;
            default:
                System.out.println("没有匹配！");
                break;
        }
    }

    public static void main1(String[] args) {
        int a = 2;
        switch (a) {
            case 2:
                System.out.println("two");
                break;
            case 1:
                System.out.println("one");
                break;
            default:
                System.out.println("没有匹配！");
                break;
        }
    }
}
